package com.run.guifeng.controller.managerController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.run.guifeng.model.dto.ManagerDto;
import com.run.guifeng.model.entity.GoodsInfo;
import com.run.guifeng.model.entity.Order;
import com.run.guifeng.model.entity.User;
import com.run.guifeng.service.OrderService;
import com.run.guifeng.service.UserService;
import com.run.guifeng.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
public class ManagerController {

    @Autowired
    private OrderService orderService;
    @Autowired
    private UserService userService;
    /**
     * 上架商品
     * 	- 下架商品
     * 	- 订单管理
     * 	- 商品修改
     */
    //login
    @PostMapping()
    public void login(@RequestBody ManagerDto managerDto){

    }
    //exit

    public void exit(){

    }
    //推送

    public List<GoodsInfo> pushproduct2Index(){

        return null;
    }
    //上架商品

    @PutMapping
    //TODO  管理进行鉴权
    public Result addProduct(@RequestBody GoodsInfo goodsInfo){
        //manager add product;
        return Result.success("add success");
    }
    //下架商品
    @PutMapping("/down/{id}")
    public Result downProduct(@PathVariable Integer id){
        // 修改商品 goods_sell_status

        return Result.success("down product success");
    }
    @GetMapping("/orders/{page}/{status}")
    public Result getOrdersByStatus(@PathVariable("page") Integer page,
                                    @PathVariable ("status")Integer status){
        Page<Order> Orders = orderService.searchOrdersByStatus(page,status);
        Result result = Result.success("success");
        result.setData(Orders);
        return result;
    }

    @GetMapping("/search/{content}")
    public Result searchUserList(@PathVariable String content){
        //返回list
        List<User> list = new ArrayList<>();
        list = userService.searchUserListByContent(content);
        Result resultVo = Result.success("查询成功");
//        Page<User> objectPage = new Page<>();
//        objectPage.setRecords(list);
        resultVo.setData(list);
        return resultVo;
    }
}
